package com.express.sys.controller;

import com.express.entity.UserReceipt;
import com.express.mybatis.PageResult;
import com.express.mybatis.Result;
import com.express.service.UserReceiptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 物流托号处理
 * @author 28014
 */
@Slf4j
@RestController
@RequestMapping({"/receipt"})
public class UserReceiptController {

    @Autowired
    UserReceiptService userReceiptService;

    @PostMapping({"/list"})
    public PageResult list(PageResult page) {
        return userReceiptService.query(page);
    }

    @PostMapping({"/save"})
    public Result save(@RequestBody UserReceipt userReceipt) {
        Result result = new Result();
        int save = userReceiptService.save(userReceipt);
        if(save > 0) {
            result.setData(save);
        } else {
            result.setSuccess(false);
            result.setMessage("添加失败检查是否数据重复");
        }
        return result;
    }


    @PostMapping({"/update"})
    public Result update(@RequestBody UserReceipt userReceipt) {
        Result result = new Result();
        userReceiptService.update(userReceipt);
        return result;
    }

    @GetMapping({"/delete/{id}"})
    public Result delete(@PathVariable("id") Integer id) {
        Result result = new Result();
        UserReceipt userReceipt = new UserReceipt();
        userReceipt.setId(id);
        userReceiptService.delete(userReceipt);
        return result;
    }

    @GetMapping("/test")
    public String getTest(){
        return "{\"data\":{\"specialCount\":1,\"totalBet\":150.00,\"totalWin\":60.00,\"koList\":[{\"setRate\":95,\"rate\":1280.00,\"totalBet\":12.00,\"totalWin\":153.60},{\"setRate\":95,\"rate\":453.00,\"totalBet\":42.00,\"totalWin\":190.20},{\"setRate\":95,\"rate\":3353.00,\"totalBet\":51.00,\"totalWin\":1710.00},{\"setRate\":95,\"rate\":2765.00,\"totalBet\":12.00,\"totalWin\":331.80},{\"setRate\":95,\"rate\":1280.00,\"totalBet\":12.00,\"totalWin\":153.60}]},\"code\":0,\"msg\":\"成功\"}";
    }


}
